#include "File/BOSSOutputLoader.h"
#include "File/YamlLoader.h"
#include "Functions/TerminalIO.h"
#include <iostream>
#include <string>

using namespace BOSS_Afterburner::TerminalIO;
using namespace std;

/// @addtogroup Afterburner_scripts
/// @{

/// Generate histograms from branches in `TTree`s in exclusive and inclusive Monte Carlo sets and in measurement data sets.
/// @author   Remco de Boer 雷穆克 (r.e.deboer@students.uu.nl or remco.de.boer@ihep.ac.cn)
/// @date     April 30th, 2019
void PlotBranches(const char* config_file)
{
  YamlLoader conf(config_file);

  // * Determine tree name * //
  const auto& treename = conf["Tree name"];
  if(!treename) return;
  string tree = treename.as<string>().c_str();

  // * Load file * //
  const auto& filename = conf["Input file or directory"];
  if(!filename) return;
  BOSSOutputLoader file(filename.as<string>().c_str());

  // * Determine weather to load print cut flow * //
  const auto& print = conf["Settings"]["print cut flow"];
  if(!!print && print.as<bool>()) file.PrintCutFlow();

  // * Loop over sequence of branches * //
  const auto& branches = conf["Branches to plot"];
  if(!branches) return;
  for(const auto& plot : branches)
    file.Draw(tree, plot);
}
/// @}

int main(int argc, char* argv[])
{
  CheckMainArguments(argc, argv, 1);
  PlotBranches(argv[1]);
  return 0;
}